package com.max.back.pharmacy.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.max.back.entity.PrescriptionItem;
import com.max.back.pharmacy.form.PrescriptionItemForm;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface PrescriptionItemDao extends BaseMapper<PrescriptionItem> {

    @Select(value = "SELECT DISTINCT\n"+
    "\tPRESCRIPTION_ITEM.*, DRUG.NAME,\n" +
            "\tDRUG.SPECIFICATION,\n"+
            "\tDRUG.MANUFACTURER,\n"+
            "\tDRUG.USAGE_DOSAGE,\n"+
            "\tDRUG.UNIT,\n"+
            "\tDRUG.DRUG_TYPE,\n"+
            "\tDRUG.INVENTORY\n"+
            "FROM\n" +
            "PRESCRIPTION_ITEM, DRUG\n"+
            "WHERE PRESCRIPTION_ITEM.PRESCRIPTION_ID=#{id} \n"+
            "AND DRUG.ID =PRESCRIPTION_ITEM.DRUG_ID\n"+
            "AND DRUG.DELETED=0\n"+
            "AND PRESCRIPTION_ITEM.PAY_STATUS=2002\n"+
            "AND PRESCRIPTION_ITEM.DELIVERY_STATUS=3001"
    )
    List<PrescriptionItemForm> listPrescriptionItemForm(@Param("id")String id);

    @Select(value = "SELECT DISTINCT\n"+
            "\tPRESCRIPTION_ITEM.*, DRUG.NAME,\n" +
            "\tDRUG.SPECIFICATION,\n"+
            "\tDRUG.MANUFACTURER,\n"+
            "\tDRUG.USAGE_DOSAGE,\n"+
            "\tDRUG.UNIT,\n"+
            "\tDRUG.DRUG_TYPE,\n"+
            "\tDRUG.INVENTORY\n"+
            "FROM\n" +
            "PRESCRIPTION_ITEM, DRUG\n"+
            "WHERE PRESCRIPTION_ITEM.PRESCRIPTION_ID=#{id} \n"+
            "AND DRUG.ID =PRESCRIPTION_ITEM.DRUG_ID\n"+
            "AND DRUG.DELETED=0\n"+
            "AND PRESCRIPTION_ITEM.PAY_STATUS=2002\n"+
            "AND PRESCRIPTION_ITEM.DELIVERY_STATUS=3002"
    )
    List<PrescriptionItemForm> listRepercussion(@Param("id")String id);

    @Select(
            value = "SELECT DISTINCT\n"+
                    "\tPRESCRIPTION_ITEM.*, DRUG.NAME,\n" +
                    "\tDRUG.SPECIFICATION,\n"+
                    "\tDRUG.MANUFACTURER,\n"+
                    "\tDRUG.USAGE_DOSAGE,\n"+
                    "\tDRUG.UNIT,\n"+
                    "\tDRUG.DRUG_TYPE,\n"+
                    "\tDRUG.INVENTORY\n"+
                    "FROM\n" +
                    "PRESCRIPTION_ITEM, DRUG\n"+
                    "WHERE PRESCRIPTION_ITEM.PRESCRIPTION_ID=#{id} \n"+
                    "AND DRUG.ID =PRESCRIPTION_ITEM.DRUG_ID\n"+
                    "AND DRUG.DELETED=0\n"
    )
    List<PrescriptionItemForm> listAll(@Param("id")String id);
}
